/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package networkrespnse;

import core.Order4;
import utils.StringUtils;
import utils.Utils;

/**
 *
 * @author Kvest
 */
public class OrderResponse4 extends OrderResponse3 {
    public OrderResponse4(int id) {
        super(id);
    }
    
    public OrderResponse4(byte[] data) {
        super(ORDER_RESPONSE4);
        order = new Order4(-1);

        parse(data);
    }
    
    public void createOrder() {
        order = new Order4(-1);
    }
    
    public int parse(byte[] data, int offset) {
        byte[] buffer4 = new byte[4];
        
        //sourceWhence
        System.arraycopy(data, offset, buffer4, 0, buffer4.length);
        offset += buffer4.length;
        int strSize = Utils.byteToInt(buffer4);
        byte[] buffer = new byte[strSize];
        System.arraycopy(data, offset, buffer, 0, buffer.length);
        offset += buffer.length;
        ((Order4)order).sourceWhence = StringUtils.bytesToStr(buffer);
        
        //orderCostForDriver;
        buffer = new byte[16];
        System.arraycopy(data, offset, buffer, 0, buffer.length);
        offset += buffer.length;
        ((Order4)order).orderCostForDriver = Utils.byteToDecimal(buffer);
                
        //canFirstForAnyParking;
        ((Order4)order).canFirstForAnyParking = (data[offset++] != 0);
                
        //distanceToPointOfDelivery;
        System.arraycopy(data, offset, buffer, 0, buffer.length);
        offset += buffer.length;
        ((Order4)order).distanceToPointOfDelivery = Utils.byteToDecimal(buffer);
                
        //concessional;
        ((Order4)order).concessional = (data[offset++] != 0);
                
        buffer4 = null;
        buffer = null;
        
        return super.parse(data, offset);
    }
}
